package wiki.xsx.core.bytecode.handler;

import wiki.xsx.core.bytecode.BytecodeUtil;
import wiki.xsx.core.bytecode.enums.ExecuteType;
import wiki.xsx.core.bytecode.model.Annotations;
import wiki.xsx.core.bytecode.transformer.ClassAnnotationTransformer;

/**
 * 类助手
 *
 * @author xsx
 * @date 2023/2/20
 * @since 1.8
 * <p>
 * Copyright (c) 2023 xsx All Rights Reserved.
 * easy-bytecode is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 * http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 * </p>
 */
public class ClassHandler extends AbstractHandler {

    /**
     * 添加或更新注解
     *
     * @param className   类名称
     * @param annotations 注解
     */
    public void addOrUpdateAnnotation(String className, Annotations... annotations) {
        this.check(className, annotations);
        BytecodeUtil.transform(
                new ClassAnnotationTransformer(
                        this.isWrite,
                        this.fileDir,
                        ExecuteType.ANNOTATION_CLASS_ADD_OR_UPDATE,
                        className,
                        annotations
                )
        );
    }

    /**
     * 删除注解
     *
     * @param className   类名称
     * @param annotations 注解
     */
    public void removeAnnotation(String className, Annotations... annotations) {
        this.check(className, annotations);
        BytecodeUtil.transform(
                new ClassAnnotationTransformer(
                        this.isWrite,
                        this.fileDir,
                        ExecuteType.ANNOTATION_CLASS_REMOVE,
                        className,
                        annotations
                )
        );
    }
}
